import { message } from 'antd';
import { register } from '@/services/user/register';

const RegisterModel = {
  namespace: 'register',
  state: {
    status: undefined,
  },
  effects: {
    *submit({ payload }, { call, put }) {
      const response = yield call(register, payload);
      if (response.success === true) {
        yield put({
          type: 'saveStatus',
          payload: response.success,
        });
      } else {
        message.error(`注册失败！${response.message}`);
      }
    },
  },
  reducers: {
    saveStatus(state, { payload }) {
      return { ...state, success: payload };
    },
  },
};
export default RegisterModel;
